package com.ash.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/2 21:00
 * @Author : Chen Chao
 * @File : connection.com.ash.connection.Connection.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 数据库连接
 */
public class MyConnection {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*1.加载驱动，一般项目可以省略，它会自动导入，但是web项目不可以*/
        Class.forName("com.mysql.cj.jdbc.Driver");
        /*2.获取连接对象*/
        /*2.1 url*/
        String url = "jdbc:mysql://www.cc.com:3306/kk?characterEncoding=utf8&" +
                "useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true" +
                "&allowPublicKeyRetrieval=true";
        /*2.2 用户名*/
        String user="root";
        /*2.3 密码*/
        String password="123456";
        /*2.4建立连接并打印连接*/
        Connection connection = DriverManager.getConnection(url, user, password);
        System.out.println(connection);
        /*com.mysql.jdbc.JDBC4Connection@4b9af9a9*/

        /*用于在navicat中查看连接*/
        //Thread.sleep(55000);


    }
}
